import requests
import json
import unittest
import datetime  # 导入日期时间模块
import time
from Comm.data import read_excel
from Config.Config import *


class Test(unittest.TestCase):

  @classmethod
  def setUpClass(cls):
    cls.access_token = globals()

  def test_001_bug_servicegoods(self):
    today = datetime.date.today()  # 获得今天的日期
    tomorrow = today + datetime.timedelta(days=1)
    list_data = read_excel('D:\\qxdj-autotest\\autotest\\Comm\\buggoodsbooking.xlsx')
    headers = {
      'Content-Type': 'application/json'
              }
    url = "https://day.manage.qxdaojia.com/api"+ list_data[1]['url']
    data = json.loads(list_data[1]['data'])
    data['timeSources'][0]['day'] = str(tomorrow)
    #str.replace(data['day'],datetime.datetime.strftime(tomorrow,'%Y-%m-%d'))
    #print(type(data['day']))
    method = list_data[1]['method']
    expect_res = list_data[1]['expect_res']  # 期望数据
    data1 = json.dumps(data)  # 将 Python 对象编码成 JSON 字符串
    print(data)
    res = requests.request(method=method, url=url, data=data1.encode('utf-8'), headers=headers)
    #req = requests.request("POST", url, data=json.dumps(data),headers=headers)
    print(res.text)
    #self.access_token[0] = req["data"]["access_token"]


if __name__ == '__main__':
    unittest.main(verbosity=2)
